// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  return cloud.callFunction({
    name: "model_default_institution",
    data: {
      op: "update",
      u_id: event.user_id,
      i_id: event.institution_id
    }
  }).then(res => {
    if (res.result.stats.updated == 1) {
      return cloud.callFunction({
        name: "model_default_institution",
        data: {
          op: "select",
          key: "u_id",
          value: event.user_id
        }
      }).then(res => { return res.result.data; })
    }
    return 0;
  })
}